package de.bk.timecalc.midlet.statemachine;

import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.TextBox;
import javax.microedition.lcdui.TextField;

import de.bk.timecalc.midlet.Commands;

public class GuiStateHelp extends AbstractGuiState
{
  private TextBox textBoxHelp;

  GuiStateHelp(StateMachine stateMachine)
  {
    super(stateMachine);
  }

  public void init()
  {
    this.createForm();
  }

  public void enter()
  {
    this.getDisplay().setCurrent(this.textBoxHelp);
  }

  public void destroy()
  {
    this.textBoxHelp = null;
  }

  private void createForm()
  {
    String helpText = "QL Time Calc Trainer Help\n"
        + "\n\n"
        + "Background\n"
        + "\n"
        + "The QL Time Calc Trainer is an utterly useless application to train your ability to do mental arithmetic, more precisely to do some calculations specific to Quake Live (or Quake 3 Arena) in your head.\n"
        + "\n"
        + "When playing Quake Live, it's advantageous to know when certain items (Mega Health, Armor, Quad Damage) will respawn. The respawn times are fixed (for most maps) - Mega Health/Health: 35 seconds, Red/Yellow Armor: 25 seconds, Quad Damage: 2 minutes. If you know the time an item taken is taken, you can calculate when it will respawn based on the above respawn times.\n"
        + "\n"
        + "However, it is not always easy to do the math in your head while jumping around, shooting, avoiding shots etc. etc. Also, calculations based on 60 seconds (instead on 10, 100, 1000, ...) is something you may no be used to.\n"
        + "\n\n"
        + "Usage\n"
        + "\n"
        + "The QL Time Calc Trainer is very simply. From the main menu, you can select \"Help\" to read this text, \"Options\" to set the timer direction or \"Start\" to start the trainer. Once started, you get the time from which to start (when the item is taken) and the amount you have to subtract/add (depending on timer direction, see below), either 25 seconds, 35 seconds or 2 minutes. You can enter your answer by typing up to 4 digits. If you type \"1435\" this will be interpreted as 14:35. You can type less digits (but you need to type at least 2). \"413\" will be interpreted as 4:13, \"43\" will be interpreted as 04:03.\n"
        + "\n\n"
        + "Options\n"
        + "\n"
        + "Currently, there is only one option: The direction of the timer. If your QL timer counts down to zero (default in QL, cg_leveltimerdirection 1), you should select down. This is also the default in QL Time Calc Trainer. You will have to *subtract* the respawn times. If your QL timer counts up (cg_leveltimerdirection 0), you should select up. In this case, you will have to *add* the respawn times.\n"
        + "\n\n"
        + "Score\n"
        + "\n"
        + "For each answer you get a score, depending on how correct the answer was and how long the calculation took you. You can score points even for wrong answers: if the answer is just a bit off but you answered very quickly, you receive points. This reflects the fact that most often it is not necessary to time the items 100% perfect but it is fine if you time it approximately. Being too early at the place where the item will respawn is better than being too late. In the first case, you may have to wait a few seconds, in the second case the item might already be taken.\n"
        + "\n"
        + "The maximum score is 15 in the mobile version of QL Time Calc Trainer - that would be for a correct answer given in zero seconds. Each second you need to calculate the answer costs you 1 point.\n"
        + "\n"
        + "Being slightly off decreases your score in the following way:\n"
        + "\n"
        + " * 1 second too early decreases the score by 0.1\n"
        + " * 2 seconds too early decreases the score by 0.2\n"
        + " * 3 seconds too early decreases the score by 0.4\n"
        + " * 4 seconds too early decreases the score by 0.7\n"
        + " * 5 seconds too early decreases the score by 1\n"
        + " * 6 seconds too early decreases the score by 2\n"
        + " * 7 seconds too early decreases the score by 4\n"
        + " * 8 seconds too early decreases the score by 8\n"
        + " * 9 or more seconds too early: No Points will be given\n"
        + " * 1 second too late decreases the score by 0.2\n"
        + " * 2 seconds too late decreases the score by 0.4\n"
        + " * 3 seconds too late decreases the score by 0.8\n"
        + "  * 4 seconds too late decreases the score by 1.4\n"
        + " * 5 seconds too late decreases the score by 2\n"
        + " * 6 seconds too late decreases the score by 4\n"
        + " * 7 seconds too late decreases the score by 8\n"
        + " * 8 or more seconds too late: No Points will be given\n"
        + " \n"
        + "This scoring schema never gives a negative score. Should the score calculated by the rules above be negative, you get 0 points.\n"
        + "\n\n"
        + "Statistics\n"
        + "\n"
        + "The application displays 4 \"statistical\" values:\n"
        + "\n"
        + "Time: the time you needed for the last calculation\n"
        + "Last: the points you received for the last answercalculation\n"
        + "Total: the sum of the score of all given answers\n"
        + "Average: your average score per answer (Total divided by the number of exercises you did)\n"
        + "\n\n"
        + "Miscellaneous\n"
        + "\n"
        + "The exercise are generated at random. Roughly 40% will be 25 seconds exercises, another 40% are 35 seconds exercises and only 20% are 2 minutes exercises (because these are much easier and don't really need to be trained).\n"
        + "\n"
        + "QL Time Calc Trainer was written by Bastian Krol (bastian.krol@web.de).\n"
        + "\n"
        + "Quake Live, Quake and Quake 3 Arena are registered trademarks of Id Software."
    //
    ;
    this.textBoxHelp = new TextBox("Help", helpText, helpText.length(),
        TextField.UNEDITABLE);

    CommandListener commandListener = new DefaultCommandListener(this);
    this.textBoxHelp.setCommandListener(commandListener);
    this.textBoxHelp.addCommand(Commands.exit);
  }
}
